package com.snailframework.gateway.senetinel;

import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter;
import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.result.view.ViewResolver;

import java.util.List;

/**
 * @author: zgadmin(zhangge)
 * @Date: 2023/8/31 14:14
 * @Version: 1.0.0
 */
@Configuration
public class SentinelGatewayConfig {


    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler(ObjectProvider<List<ViewResolver>> viewResolversProvider, ServerCodecConfigurer serverCodecConfigurer) {
        return new SentinelGatewayBlockExceptionHandler(viewResolversProvider.getIfAvailable(), serverCodecConfigurer);
    }

//    @Bean
//    @Order(Ordered.HIGHEST_PRECEDENCE)
//    GlobalFilter sentinelGatewayFilter() {
//        return new SentinelGatewayFilter();
//    }

}